import java.util.*;

public class Solution2250 {

    static class State{
        int id;
        int x;
        int y;

        public State(int id, int x, int y) {
            this.id = id;
            this.x = x;
            this.y = y;
        }
    }

    static class BIT{
        int n;
        int[] h;

        public BIT(int n){
            this.n=n;
            h=new int[n+1];
        }

        public int query(int x){
            int t=0;
            while (x>0){
                t+=h[x];
                x-=lowbit(x);
            }
            return t;
        }

        private int lowbit(int x) {
            return x&(-x);
        }

        public void update(int x,int d){
            while (x<=n){
                h[x]+=d;
                x+=lowbit(x);
            }
        }
    }

    public int[] countRectangles(int[][] rectangles, int[][] points) {
        Arrays.sort(rectangles, Comparator.comparingInt(a -> a[0]));
        State[] states=new State[points.length];
        for (int i=0;i<points.length;i++){
            states[i]=new State(i,points[i][0],points[i][1]);
        }
        Arrays.sort(states, Comparator.comparingInt(a -> a.x));
        TreeSet<Integer> treeSet=new TreeSet<>();
        for (int[] point : points) {
            treeSet.add(point[1]);
        }
        for (int[] rectangle : rectangles) {
            treeSet.add(rectangle[1]);
        }
        int id=0;
        Map<Integer,Integer> map=new HashMap<>();
        for (Integer integer : treeSet) {
            id++;
            map.put(integer,id);
        }
        BIT bit=new BIT(id);
        int cur=rectangles.length-1;
        int[] ans=new int[points.length];
        for (int i=states.length-1;i>=0;i--){
            while (cur>=0 && rectangles[cur][0]>=states[i].x){
                bit.update(map.get(rectangles[cur][1]),1);
                cur--;
            }
            ans[states[i].id]=rectangles.length-cur-1-bit.query(map.get(states[i].y)-1);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution2250().countRectangles(new int[][]{{1, 1}, {2, 2}, {3, 3}}, new int[][]{{1, 3}, {1, 1}})));
    }
}
